package com.zzj.controller;


import com.github.pagehelper.PageInfo;
import com.zzj.bean.TabOrder;
import com.zzj.service.TabOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * InnoDB free: 8192 kB 前端控制器
 * </p>
 *
 * @author 花
 * @since 2022-03-04
 */
@RestController
@RequestMapping("/order")
@Api
@CrossOrigin
public class TabOrderController {
    @Autowired
    private TabOrderService tabOrderService;

    @GetMapping("/getAllOrder")
    @ApiOperation("管理员专属,获取所有信息")
    public PageInfo<TabOrder> getAllOrder(
            @RequestParam(required = false,defaultValue = "1") int pageNum,
            @RequestParam(required = false,defaultValue = "5") int pageSize
    ) {
        return tabOrderService.getAllOrders(pageNum,pageSize);
    }

/*    @GetMapping("/getOrder")
    @RequestMapping("获取订单信息")
    public List<TabOrder> getOrder() {
        QueryWrapper<TabOrder> wrapper = new QueryWrapper<>();
        wrapper.eq("ostatus", "已完成");
        return tabOrderService.list(wrapper);
    }*/

    @PostMapping("/addOrder")
    @ApiOperation("增加订单")
    public boolean addOrder(@RequestBody TabOrder order) {
        System.out.println("order = " + order);
//        order.setOstatus("订单已发送");
//        order.setOoo("1");
//        return tabOrderService.save(order);
        return tabOrderService.addOrder(order);
    }

    @DeleteMapping("/delOrder/{oid}/{ooo}")
    @ApiOperation("删除订单")
    public boolean delOrder(@PathVariable("oid") String oid,@PathVariable("ooo") String ooo) {
        TabOrder order = tabOrderService.getById(oid);
        order.setOoo(ooo);
        return tabOrderService.updateById(order);
    }


}

